package com.server.rpcserver;

import com.common.serialize.impl.KryoSerializer;
import com.common.service.DeptService;
import com.common.service.UserService;
import com.common.tools.CommonTool;
import com.server.rpcserver.impl.NettyRPCServer;
import com.server.service.impl.DeptServiceImpl;
import com.server.service.impl.UserServiceImpl;
import com.server.zk.ZkService;

import java.net.*;
import java.util.Enumeration;

/**
 * @author Zixiang Hu
 * @description
 * @create 2021-03-01-15:24
 */
public class NettyServerMain {
    public static void main(String[] args) throws UnknownHostException {
        // 传入待扫描的包
        ServiceProvider serviceProvider = new ServiceProvider("com.server.service");
        String localIP = CommonTool.getLocalIPList();
        int port = 7777;
        // 实例化zk服务
        ZkService zkService = new ZkService("192.168.106.130:2181");
        InetSocketAddress socketAddress = new InetSocketAddress(localIP, port);
        // 将该服务器能提供的服务和本机ip注册到zk
        zkService.registerService(UserService.class.getName(), socketAddress);
        zkService.registerService(DeptService.class.getName(), socketAddress);
        RPCServer server = NettyRPCServer.builder().serviceProvider(serviceProvider)
                .serializer(new KryoSerializer())
                .build();
        server.start(port);
    }
}
